import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('./files/通威股份.csv', index_col='date', parse_dates=['date'])[['open','close','low','high']]

df['ma5'] = np.nan
df['ma30'] = np.nan

for i in range(4, len(df)):
  df.loc[df.index[i], 'ma5'] = df['close'][i-4:i+1].mean()

for i in range(29, len(df)):
  df.loc[df.index[i], 'ma30'] = df['close'][i-29:i+1].mean()

# 简单方法求均线
df['ma5_T'] = df['close'].rolling(window=5).mean()
df['ma30_T'] = df['close'].rolling(window=30).mean()

print(df)
